package com.xmg.mgrsite.base;

import com.xmg.p2p.base.domain.RealAuth;
import com.xmg.p2p.base.query.RealAuthQueryObject;
import com.xmg.p2p.base.service.RealAuthService;
import com.xmg.p2p.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @BelongsProject: ssm-jinrong
 * @BelongsPackage: com.xmg.mgrsite.base
 * @author: Andy
 * @date: 2021.3.23 15:34
 * @Description: 实名认证的控制器
 * @since JDK 1.8
 */
@Controller
public class RealAuthController {
    @Autowired
    private RealAuthService realAuthService;

    @RequestMapping("realAuth")
    public String toRealAuth(Model model, @ModelAttribute("queryForCount") RealAuthQueryObject queryForCount){
        // 当用户第一次打开实名认证时，RealAuthQueryObject肯定为空。添加为空就会查出所有的信息了
        model.addAttribute("pageResult",realAuthService.query(queryForCount));
        return "realAuth/list";
    }

    /**
     * 执行审核操作
     * @return
     */
    @ResponseBody
    @RequestMapping("realAuth_audit")
    public JSONResult apply(Long id,String remark,int state){
        JSONResult json = new JSONResult();
        try {
            this.realAuthService.audit(id,remark,state);
        }catch (Exception e){
            e.printStackTrace();
            json.setSuccess(false);
            json.setMsg("审核失败！");
        }
        return json;
    }

}
